# base.py

import cPickle as pickle

from ot_simulator.tk_gui.method_interfaces import *
from ot_simulator.tk_gui.input_fields import *

class base(object):
    methods = (
        method_with_parameters("Save",
                               lambda obj, filename: obj.save(filename),
                               output_filename("Save as",
                                               filetypes=(
                                                   ("foo file", "foo"),
                                                 ))),
      )

    def __init__(self, name):
        self.name = name

    def save(self, filename = None):
        if filename is None:
            filename = self.name + '.' + self.extension()
        with open(filename, "w") as f:
            pickle.dump(self, f)

    def extension(self):
        return type(self).__name__
